<?php
/**
 * Created by PhpStorm.
 * User: zhangtao
 * Date: 16-5-21
 * Time: 下午12:54
 */

namespace Home\Controller;


use Think\Controller;

class StoreController extends Controller
{
    public function index()
    {
    }

    public function storelist()
    {
        $store = M('Store');
        $storeList = $store->page(I('post.page'), I('post.limit'))->select();
        $this->ajaxReturn($storeList);
    }

    public function storedetail()
    {
        $store = M('Store');
        $sid = I('post.sid');
        $storeData = $store->where(array('id' => $sid))->find();
        $storeType = $store->field(array('id', 'type'))->table('__DISHTYPE__')->where(array('store_id' => $sid))->select();
        /*foreach ($storeType as $k => $v) {
            $dish = $store->table('__DISH__')->where(array('type_id' => $v['id'], 'store_id' => $sid))->select();
            $storeType[$k]['dish']=$dish;
        }*/
        $storeData['dishtype'] = $storeType;
        //echo json_encode($storeData, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
        $this->ajaxReturn($storeData);
    }

    public function storedish()
    {
        $store = M('Store');
        $sid = I('post.sid');
        $dish = $store->table('__DISH__')->where(array('store_id' => $sid))->select();
         //echo json_encode($dish, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
        $this->ajaxReturn($dish);
    }
    public function comments()
    {
        $comments = M('Comments');
        $commentsList = $comments->field('store_id',true)->where(['store_id'=>I('post.sid')])->select();
        $this->ajaxReturn($commentsList);
    }
}